package org.linlinjava.litemall.web.controller;

import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.web.annotation.LogAnno;
import org.linlinjava.litemall.web.annotation.LoginUser;
import org.linlinjava.litemall.web.dto.AdminScanDTO;
import org.linlinjava.litemall.web.service.WebScanPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * 网络扫描支付控制器
 *
 * @author yliyun
 * @description：扫码支付controller
 * @date 2022/09/14
 */
@RestController
@RequestMapping("/web/scan")
public class WebScanPayController {
    /**
     * web代码支付服务
     */
    @Autowired
    private WebScanPayService webCodePayService;

    /**
     * 扫描支付
     *
     * @param dto    dto
     * @param userId 用户id
     * @return {@link Object}
     */
    @PostMapping("/pay")
    @LogAnno
    public Object scanPay(@Valid @RequestBody AdminScanDTO dto, @LoginUser Integer userId){
        if(userId == null){
            return ResponseUtil.unlogin();
        }
        return webCodePayService.pay(dto);
    }
}
